// =============================================================================
import java.lang.reflect.*
class A1 {
}
assert A1.name == 'A1'
assert new A1().class.name == 'A1'

class B1 extends A1 {
}
assert B1.superclass.name == 'A1'

// =============================================================================
interface A2 {
}
interface B2 {
}
class C2 implements A2, B2 {
}
def interfaces = []
C2.interfaces.each{ interfaces << it.name }
assert interfaces == [ 'A2', 'B2', 'groovy.lang.GroovyObject' ]

assert A2.isInterface()

// =============================================================================
// Fields
class A3 {
	String a0 = 'a0'
	public String a1 = 'a1'
	protected String a2 = 'a2'
	private String a3 = 'a3'
	static String a4 = 'a4'
	
	void method0() {}
	public void method1() {}
	protected void method2() {}
	private void method3() {}
	static void method4() {}

	public String sayHello(String name) {return 'Hello ' + name + '!'}
	def greeting(name) {return 'Hello ' + name + '!'}
}
// By default, each class has a "__timeStamp" property
def fields = []
A3.fields.each{ fields << it.name}
assert fields == ['a1', '__timeStamp']
assert A3.getField('a1').type.name == 'java.lang.String'

println 'A3.declaredFields:[' 
println A3.declaredFields.each{ println it }
println ']'
assert A3.getDeclaredField('a0').name == 'a0'
assert A3.getDeclaredField('a0').type.name == 'java.lang.String'
assert A3.getDeclaredField('a0').getModifiers() == Modifier.PRIVATE

// =============================================================================
// Methods

// print public methods
println 'A3.methods ['
A3.methods.each{ println it}
println ']'

// print declared methods
println 'A3.declaredMethods ['
A3.declaredMethods.each{ println it}
println ']'

// invokd method
def method = A3.getDeclaredMethod('sayHello', [String] as Class[])
assert method.invoke(new A3(), ['kongxx'] as Object[]) == 'Hello kongxx!'

// invokd method
method = A3.getDeclaredMethod('greeting', [Object] as Class[])
assert method.invoke(new A3(), ['kongxx'] as Object[]) == 'Hello kongxx!'
